﻿/*!
 *  Copyright (c), 上海沃恩信息科技有限公司.
 *  All rights reserved.
 *  Licensed under BSD (https://www.pittypat.work/bsd.html).
 */

using System.Collections.Generic;
using System.IO;
using Pittypat;

namespace Waln.Notifying.Unread
{
    /// <summary>
    /// 表示一条通知消息。
    /// </summary>
    sealed class Notification : INotification
    {
        // 一个空的通知消息列表。
        static readonly IList<INotification> EmptyList = new INotification[0];

        /// <summary>
        /// 将数据服务中查询到的通知列表转换为 Notification 表示的通知列表。
        /// </summary>
        /// <param name="list">来自数据服务的通知列表。</param>
        /// <returns>由 Notification 构成的通知列表。</returns>
        internal static IList<INotification> From(DataList<Data.Notification> list)
        {
            if (list == null || list.Count == 0)
            {
                return EmptyList;
            }

            IList<INotification> items = new List<INotification>(list.Count);

            foreach (var item in list)
            {
                items.Add(new Notification(item));
            }

            return items;
        }

        private Data.Notification not;

        private Notification(Data.Notification not)
        {
            this.not = not;
        }

        @string? INotification.FuncUrl
        {
            get
            {
                return this.not.FuncUrl;
            }
        }

        @string? INotification.Group
        {
            get
            {
                return this.not.Group;
            }
        }

        uuid? INotification.Id
        {
            get
            {
                return this.not.Id;
            }
        }

        datetime? INotification.ReceiveTime
        {
            get
            {
                return this.not.ReceiveTime;
            }
        }

        @string? INotification.SenderFaceUrl
        {
            get
            {
                return this.not.SenderFaceUrl;
            }
        }

        @string? INotification.SenderName
        {
            get
            {
                return this.not.SenderName;
            }
        }

        @string? INotification.Summary
        {
            get
            {
                return this.not.Summary;
            }
        }

        @string? INotification.Title
        {
            get
            {
                return this.not.Title;
            }
        }

        int8? INotification.Urgency
        {
            get
            {
                return this.not.Urgency;
            }
        }

        void IJson.Write(TextWriter writer)
        {
            this.not.Write(writer);
        }
    }
}
